

function check_keywords(keywords, cb) {
	if(!keywords)
		return;
	var url = '?';
	params = {'action':'check', 'keywords':keywords};
	jQuery.post(url, params, function(result){
		if(!result){
			show_result('自动检查正常, 仍需要人工检查');
			return;
		}
		if(cb)
			cb(result);
		show_result(result);
	});
}

function format_keywords(el, format){
	var keywords = el.value;
	if(!keywords)
		return;
	var url = 'keywords.php';
	params = {'action':'format', 'keywords':keywords, 'format':format};
	jQuery.post(url, params, function(result){
//		show_result(result);
		el.value = result;
	});
}

function unique_keywords(el, deep){
	var keywords = el.value;
	if(!keywords)
		return;
	var url = '?';
	params = {'action':'unique', 'keywords':keywords, 'deep':deep};
	jQuery.post(url, params, function(result){
		el.value = result;
	});
}

function show_result(result){
	if(!result)
		return;
	if($('div.result').length)
		$('div.result').html(result);
	else if(typeof $.fancybox === 'function')
		$.fancybox(result);
	else
		alert(result);
}


function render_gmails(form){
	var $gmail = form.gmail.value;
	if(!$gmail || !/^\s*[\w\.@\-]{6,}\s*$/.test($gmail)){
		show_result('gmail格式不正确, 或者长度少于6. @gmail.com可以省略');
		return;
	}
	var url = '?';
	var params = {'action':'gmail', 'gmail':$gmail};
	var all = form.alldot.checked;
	var one = form.onedot.checked;
	var two = form.twodot.checked;
	var three = form.threedot.checked;
	params['all'] = all === true ? 1 : '';
	params['one'] = one === true ? 1 : '';
	params['two'] = two === true ? 1 : '';
	params['three'] = three === true ? 1 : '';
	jQuery.post(url, params, function(result){
		form.emails.value = result;
	});
}

function render_chong_emails(form){
	var $gmail = form.gmail.value;
	if(!$gmail || !/^\s*[\w\.@\-]{6,}\s*$/.test($gmail)){
		show_result('gmail格式不正确');
		return;
	}
	var pass = prompt('邮箱密码: ');
	if(!pass || !/^\s*[\u0000-\u00ff]+\s*$/.test(pass)){
		if(pass)
			show_result('无效密码');
		return;
	}
	form.pass.value = pass;
	form.action.value='chong';
	form.submit();
}

